package com.hemi.rhet.html;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import android.app.Activity;

import com.hemi.rhet.js.JavaScriptUtil;
import com.hemi.rhet.util.ApplicationContext;

public class TopicList {

	public String compile(Activity act, String template,String jsondata)
	{
		String templateContent  = JavaScriptUtil.getJsContentFromFile(act, template);
		return templateContent.replace("#{data}", jsondata==null?"[]":jsondata).replace("#{domain}", ApplicationContext.DOMAIN);
	}
	
	public String compile(Activity act, String template,String jsondata,HashMap<String,String> map)
	{
		String templateContent  = compile(act,   template,  jsondata);
		if(map!=null)
		{
			Set keys = map.keySet();
			if(!keys.isEmpty())
			{
				Iterator<String> it = keys.iterator();
				while(it.hasNext())
				{
					String key = it.next();
					String value=  map.get(key);
					String park = "#{"+key+"}";
					templateContent=templateContent.replace(park, value.toString());
					 
				}
			}
		}
		return templateContent;
	}
	
	public static TopicList createNew(){
		return new TopicList();
		
	}
}
